/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.logicwin.RobotTravel;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

import com.logicwin.RobotTravel.Screens.FullImageView;
import com.logicwin.RobotTravel.utils.ConfigUtils;
import java.util.LinkedList;

import java.util.List;


/**
 *
 * @author chapeng
 */
public class IntroDialogTabPic extends Activity
{

    private GridView mGridView;
    //private TabPicAdapter mTabPicAdapter;
    
    private LinkedList<Drawable> views = new LinkedList<Drawable>();



    @Override
    protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.tab_pic_home);
	
	    final String sceen = this.getIntent().getExtras().getString("sceen");
	    Resources res = this.getResources();
	    Integer[] previews = ConfigUtils.getPreviewDrawable(sceen);
	    
	    for (int index = 0; index < previews.length; index++)
	    	views.add(res.getDrawable(previews[index]));
	
	    mGridView = (GridView) findViewById(R.id.tab_pic_gridview);
	    mGridView.setAdapter(new TabPicAdapter(views));
	    mGridView.setOnItemClickListener(new OnItemClickListener() {
			
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Intent intent = new Intent(IntroDialogTabPic.this, FullImageView.class);
				intent.putExtra("sceen", sceen);
				intent.putExtra("position", position);
				startActivity(intent);
			}
		});
    }


private class TabPicAdapter extends BaseAdapter {
    private List<Drawable> views;
    
    public TabPicAdapter() {
    }

    public TabPicAdapter(List<Drawable> views) {
    	this.views = views;
    }

    public final int getCount() {
    	return views.size();
    }

    public final Object getItem(int position) {
    	return views.get(position);
    }

    public final long getItemId(int position) {
    	return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
    	ImageView view = new ImageView(IntroDialogTabPic.this);
    	view.setImageDrawable(views.get(position));
    	return view;
    }
}
    /*if (convertView == null) {
    i = new ImageView(Grid1.this);
    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
    i.setLayoutParams(new GridView.LayoutParams(50, 50));
    } else {
    i = (ImageView) convertView;
    return i;
    }*/


    
    /*
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.intro_pic);

        String sceen = this.getIntent().getExtras().getString("sceen");
        Resources res = this.getResources();
        ImageView view = (ImageView)this.findViewById(R.id.intro_pic_view);
        view.setImageDrawable(res.getDrawable(ConfigUtils.getDrawable(sceen, 1)));
    }*/
}
